package p.ithorns.integration.aop.introduction;

import org.aopalliance.intercept.MethodInvocation;
import org.springframework.aop.IntroductionInterceptor;

/**
 * AnimalIntroductionInterceptor
 * TODO ithorns
 *
 * @author Ht.L
 * @date 2024-03-10 14:37
 * @since 1.0.0
 */
public class AnimalIntroductionInterceptor implements IntroductionInterceptor, Animal {

    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        if (implementsInterface(invocation.getMethod().getDeclaringClass())) {
            return invocation.getMethod().invoke(this, invocation.getArguments());
        }
        return invocation.proceed();
    }

    @Override
    public boolean implementsInterface(Class<?> intf) {
        return intf.isAssignableFrom(this.getClass());
    }

    @Override
    public void eat() {
        System.out.println("Animal eat");
    }

}